package com.nulldev.util.io.util.test;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.io.IOUtils;
import com.nulldev.util.io.util.BufferManager.Buffer;

public class BuffersTest {

	public static void main(String[] args) {
		JVM.println("Warming up...");
		IOUtils.getBufferManager().awaitFree().free();
		final long s = System.currentTimeMillis();
		final Buffer buf = IOUtils.getBufferManager().awaitFree();
		final long e = System.currentTimeMillis();
		JVM.println("buf: " + buf);
		JVM.println("awaitFree: " + (e - s) + " ms");
		JVM.println("=> Preallocating.");
		JVM.println("prealloc: " + buf.tryPreallocate());
		if (buf.inUse()) {
			JVM.println("=> Already in use...");
		} else {
			JVM.println("=> Using.");
			JVM.println("use: " + buf.use());
		}
		JVM.println("=> Freeing.");
		buf.free();
		JVM.println("free: " + buf);
		JVM.println("state: " + buf);
	}

}
